﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Status5.aspx.cs" Inherits="WebApplication2.Web.Status" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <script src="../../lib/layui/layui.js"></script>
    <link href="../../css/font.css" rel="stylesheet" />
    <link href="../../css/xadmin.css" rel="stylesheet" />
    <script src="../../js/jquery-3.2.1.min.js"></script>
    <script src="../js/public.js"></script>
    <script src="../js/xadmin.js"></script>
</head>
<body>
    <div class="x-body">
        <div class="layui-row">
            <form class="layui-form layui-col-md12 x-so">
                <input type="text" id="projectName" placeholder="请输入项目名" autocomplete="off" class="layui-input">
                <input value="搜索" class="layui-btn " lay-submit lay-filter="search" type="submit">
                <hr class="hr20">
            </form>
        </div>

        <table class="layui-hide" id="demo1" lay-filter="demo">
            <script type="text/html" id="option">
                <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
            </script>
        </table>

    </div>
    <script>
        layui.use('table', function () {
            var table = layui.table;
            var layer = layui.layer;
            var form = layui.form;

            //监听‘操作’列里的按钮
            table.on('tool(demo)', function (obj) {
                var data = obj.data;//获取当前行数据
                var layEvent = obj.event;//获得lay-enet对应的值
                var tr = obj.tr;

                if (obj.event === 'del') {
                    layer.confirm('删除后将完全删除该项目的资料，继续么?', function (index) {
                        obj.del();
                        layer.close(index);
                        //layer.close(index);
                        //向服务器发出删除Ajax请求
                        var objdel = new Object();
                        objdel.id = data.Id;
                        objdel.name = data.Name;

                    
                        //$(this).parents("tr").remove();
                        myAjax("projectHandler.ashx", "delete", objdel, false, function (data) {
                           
                            if (data.Code == 1) {
                                layer.msg('删除成功');
                            }

                        });
                    });
                }
            });

            table.on('edit(demo)', function (obj) { //注：edit是固定事件名，test是table原始容器的属性 lay-filter="对应的值"
                console.log(obj.value); //得到修改后的值
                console.log(obj.field); //当前编辑的字段名
                console.log(obj.data); //所在行的所有相关数据  
                console.log('触发了事件');
            });

            //监听行单击事件
            table.on('row(demo)', function (obj) {
                console.log(obj.tr) //得到当前行元素对象
                console.log(obj.data) //得到当前行数据
                //obj.del(); //删除当前行
                //obj.update(fields) //修改当前行数据
            });

            //监听行双击事件
            table.on('rowDouble(demo)', function (obj) {
                //obj 同上
                console.log(obj.data) //得到当前行数据
            });


            form.on('submit(search)', function (data) {
                var obj = new Object();
                obj.name = $("#projectName").val();
                obj.oprator = 'admin';
                //先查询，再选中删除
                myAjax("projectHandler.ashx", "searchByName", obj, false, function (data) {
                    console.log(data)

                    table.render({
                        elem: '#demo1'
                        , cols: [[ //标题栏
                            { field: 'Id', title: 'ID', sort: true }
                            , { field: 'InputTime', title: '引入日期' }
                            , { field: 'Name', title: '项目名' }
                            , { field: 'UserArea', title: '使用区域' }
                            , { field: 'ChargeMan', title: '负责人' }
                            , {
                                field: 'Status', title: '当前状态', width: 90, templet: function (d) {
                                    if (d.Status == 1) {
                                        return '设计'
                                    }
                                    else if (d.Status == 0) {
                                        return '方案评审'
                                    }
                                    else if (d.Status == 2) {

                                        return '加工'
                                    }
                                    else if (d.Status == 3) {
                                        return '装备调试'
                                    }
                                    else if (d.Status == 4) {
                                        return '已完成'
                                    }
                                }
                            }//此处使用了layui模板引擎
                            , { field: 'option', title: '操作', templet: "#option", unresize: true, width: 80 }

                        ]]
                        , data: data.Obj
                        , even: true
                        //, page: true //是否显示分页
                        //, limits: [5, 7, 10]
                        //, limit: 5 //每页默认显示的数量
                    });
                });
                return false;
            });

        });
    </script>

</body>

</html>
